package com.zking.frame.zc;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

import com.zking.db.BaseDao;
import com.zking.utils.MyCalendar;
import com.zking.utils.StringUtils;
import com.zking.utils.TableUtils;
/**
 * 入库
 * @author ZC
 *
 */
public class MyFrame extends JDialog {

	/**
	 * **
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel pl;
	// 美化包
	{
		try {
			BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
			org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//北部
	private JPanel pl_north;
	private JButton bt_add_account;//增加库单
	private JButton bt_update_account;//修改库单
	private JButton bt_delete_account;//删除库单
	private JButton bt_add_goods;//增加商品
	private JButton bt_update_goods;//修改商品
	private JButton bt_delete_goods;//删除商品
	private JButton bt_cancel;//取消
	//中部
	private JSplitPane split_center;
	private JPanel pl_center_left;
	private JPanel pl_center_right;
	//表格
	private DefaultTableModel tableModel_left;
	private JTable table_left;
	private DefaultTableModel tableModel_right;
	private JTable table_right;
	//南部
	private JPanel pl_south;
	
	// 选中库单的时间
	private int selectRow;//所选中的行
	String[] columnNames_left= {"编号","入库单号","进货员","进货日期","货源","备注"};
	
	String[] columnNames_right= { "书号","按本折扣", "书名","会员打折",
			                      "类型","作者","初期库存","出版社",
			                      "成本价", "定价","零售价","零售折扣", 
			                      "批发价","批发折扣","会员价",
			                      "库存上限","库存下限","批发数量"};;//表格头
	private String insertOfLib="insert into arrivalregist(id,WarehousingNum,PurchasingAgent,"
			                                           + "arrivalTime,SourceOfSupply,remark) values(?,?,?,?,?,?)";
	
	private String updateOfLib="update arrivalregist set id=?,WarehousingNum=?,PurchasingAgent=?,"
                                                       + "arrivalTime=?,SourceOfSupply=?,remark=?"
                                                       + " where id=?";
	private String queryOfLib="select id,WarehousingNum,PurchasingAgent,"
                                   +  "arrivalTime,SourceOfSupply,remark "
                                   +  "from arrivalregist";
	private String insertOfBook="insert into bookinfo(id,isEveryDiscount,BookName,isMemberDiscount,"
			                                       + "type,author,startCount,publishHouse,"
			                                       + "costPrice,price,retailPrice,retailDiscount,"
			                                       + "wholsalePrice,wholDiscount,vipPrice,countMax,"
			                                       + "countMin,inventoryNums) values(?,?,?,?,?,?,"
			                                       					+ "?,?,?,?,?,?,"
			                                       					+ "?,?,?,?,?,?)";
	private String queryOfBook="select id,isEveryDiscount,BookName,isMemberDiscount,"
							        + "type,author,startCount,publishHouse,"
							        + "costPrice,price,retailPrice,retailDiscount,"
							        + "wholsalePrice,wholDiscount,vipPrice,countMax,"
							        + "countMin from bookinfo where id=?";
	private String updateOfBook="update bookinfo set isEveryDiscount=?,BookName=?,isMemberDiscount=?,"
	        + "type=?,author=?,startCount=?,publishHouse=?,"
	        + "costPrice=?,price=?,retailPrice=?,retailDiscount=?,"
	        + "wholsalePrice=?,wholDiscount=?,vipPrice=?,countMax=?,"
	        + "countMin=?,inventoryNums=?  where id=?";
	private String insertOfLibC="insert into arrivalregistcontent(libraryID,bookId,wholeSaleNum) "
																+ "values(?,?,?)";
	//边框
	private Border border=BorderFactory.createMatteBorder(0,0,3,2,Color.gray);
	//颜色
	private Color blue=new Color(0x9FB6CD);
	//日期格式化模板
	private String pattern="yyyy-MM-dd";
	//辅助，传递数据
	private List<String> LibraryInfo=new ArrayList<String>();//库单信息
	private List<String> goodsInfo=new ArrayList<String>();//商品信息
	private BaseDao base=new BaseDao();
	private int bookNum;//书号
	private int libNum;//入库单
	{
		try {
			libNum=base.getCount("select max(id) from arrivalregist")+1;
			bookNum=base.getCount("select max(id) from bookinfo")+1;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 1.显示所有库单到表格
	 */
	public void showAllLib() {
		try {
			List<Object[]> data=base.queryArrayListHandler(queryOfLib);
			for(int i=0;i<data.size();i++)
			    tableModel_left.addRow(data.get(i));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 *2. 获取一行表格数据
	 * @param selectRow 选中的行
	 * @param tableModel 对应的模型
	 * @param len        从头开始，直到第几列
	 * @return
	 */
	public List<Object> getRowdata(int selectRow,DefaultTableModel tableModel,int len) {
		List<Object> rowData=new ArrayList<Object>();
		for(int i=0;i<len;i++)
			rowData.add(tableModel.getValueAt(selectRow,i)+"");
		return rowData;
	}
	/**
	 * 3.添加数据库库单内容到面板
	 */
	public void showLibData() {
		tableModel_right.setDataVector(null, columnNames_right);//清空数据
		int  lib_id=Integer.parseInt(tableModel_left.getValueAt(table_left.getSelectedRow(),0)+"");//获取选中行（库单）
		try {
			List<Object[]> libc=base.queryArrayListHandler("select bookId,wholeSaleNum from "
					         + " arrivalregistcontent where libraryID=?",lib_id);//根据库单ID查找书籍号与批发数
			for(int i=0;i<libc.size();i++) {//找书
				Object[] books=base.queryArrayHandler(queryOfBook,libc.get(i)[0]);
				List<Object> list=new ArrayList<Object>();
				for(int j=0;j<books.length;j++) {
					list.add(books[j]);
				}
				list.add(libc.get(i)[1]);
				tableModel_right.addRow(list.toArray());
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 4.设置行数据
	 * @param selectRow
	 * @param tableModel
	 * @param params
	 */
	public  void setRowData(int selectRow,DefaultTableModel tableModel,Object... params) {
		for(int i=0;i<params.length;i++) {
			tableModel.setValueAt(params[i], selectRow,i);
		}
	}
	public MyFrame(JFrame owner,boolean modal) {
		super(owner, modal);
		Container c=getContentPane();
		c.setLayout(new BorderLayout());
        /*整个面板*/
		pl=new JPanel();
	    pl.setBackground(Color.WHITE);
	    pl.setLayout(new BorderLayout());
		
		/*顶部*/
		pl_north=new JPanel(new FlowLayout(FlowLayout.LEADING,10,15));
		pl_north.setBackground(blue);
		pl_north.setPreferredSize(new Dimension(0,50));
		c.add(BorderLayout.NORTH,pl_north);
		  //新增入库单
		bt_add_account=new JButton("新增入库单");
        bt_add_account.setPreferredSize(new Dimension(100, 30));
		bt_add_account.setFont(new Font("楷体",Font.BOLD,15));
		bt_add_account.setBackground(new Color(0xF0F0F0));
		bt_add_account.setBorder(border);
		bt_add_account.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_add_account.addActionListener(e->{
			String today=StringUtils.dateToString(new Date(),pattern);//今天
			String str=String.format("%04d",libNum);//库单号的后面一部分
			Object[] rowData={libNum+"",today.replace("-","")+str,null,today,null,null};
			tableModel_left.addRow(rowData);//添加到表格
			//添加到数据库
			try {
				base.update(insertOfLib,rowData);
				libNum++;
				JOptionPane.showMessageDialog(MyFrame.this,"增加成功");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		});
		pl_north.add(bt_add_account);
		  //修改入库单
		bt_update_account=new JButton("修改入库单");
		bt_update_account.setPreferredSize(new Dimension(100, 30));
		bt_update_account.setFont(new Font("楷体",Font.BOLD,15));
		bt_update_account.setBackground(new Color(0xF0F0F0));
		bt_update_account.setBorder(border);
		bt_update_account.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_update_account.addActionListener(e->{
			if((selectRow=table_left.getSelectedRow())!=-1) {
				//1.获取原数据,除了单号
				LibraryInfo.clear();
				for(int i=2;i<columnNames_left.length;i++) {
					LibraryInfo.add((String)tableModel_left.getValueAt(selectRow,i));
				}
				//2.弹出修改面板,并传入数据
				new  LibraryList(MyFrame.this,true,LibraryInfo);
				if(LibraryInfo.isEmpty()) return ;
				//3.拿到修改后数据，填写到面板上，并清空LibraryInfo
				for(int i=0;i<LibraryInfo.size();i++)
				    tableModel_left.setValueAt(LibraryInfo.get(i),selectRow,i+2);//从第二个数据开始修改
				//修改数据库
				List<Object> rowData=getRowdata(selectRow, tableModel_left,columnNames_left.length);
				rowData.add(tableModel_left.getValueAt(selectRow, 0));
				try {
					base.update(updateOfLib,rowData.toArray());
					JOptionPane.showMessageDialog(MyFrame.this,"修改成功");
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				LibraryInfo.clear();
			}else {
				JOptionPane.showMessageDialog(MyFrame.this,"请选中所需修改的库单");
			}
		});
		pl_north.add(bt_update_account);
		   //删除入库单  1.删除库单内容 2.删除书籍库存
		bt_delete_account=new JButton("删除入库单");
		bt_delete_account.setPreferredSize(new Dimension(100, 30));
		bt_delete_account.setFont(new Font("楷体",Font.BOLD,15));
		bt_delete_account.setBackground(new Color(0xF0F0F0));
		bt_delete_account.setBorder(border);
		bt_delete_account.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_delete_account.addActionListener(e->{
			if((selectRow=table_left.getSelectedRow())!=-1) {
				if(JOptionPane.showConfirmDialog(MyFrame.this,"确认要删除吗？", "提示", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION) {
					try {
						String  lib_id=table_left.getValueAt(selectRow, 0)+"";
						//更新书籍库存
						{
							List<Object[]> bookIDs=base.queryArrayListHandler("select bookid,wholeSaleNum from arrivalregistcontent where libraryID=?",lib_id);//查询所有库单书号,批发数
						    for(int i=0;i<bookIDs.size();i++) {
						    	int bookNum=base.getCount("select inventoryNums from bookinfo where id=?",bookIDs.get(i)[0]);//查询图书库存
						    	base.update("update bookinfo set inventoryNums=? where id=?",(int)bookNum-(int)bookIDs.get(i)[1],bookIDs.get(i)[0]);//修改图书库存
						    }
						}
						base.update("delete from arrivalregistcontent where libraryID=?",lib_id);//删除库单内容
						base.update("delete from arrivalregist where id=?",lib_id);//删除库单
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					tableModel_left.removeRow(selectRow);//移除
					tableModel_right.setDataVector(null, columnNames_right);
					JOptionPane.showMessageDialog(MyFrame.this,"删除成功");
				}   
			}else {
				JOptionPane.showMessageDialog(MyFrame.this,"请选中所需删除的库单");
			}
		});
		pl_north.add(bt_delete_account);
		   //增加商品
		bt_add_goods=new JButton("增加商品");
		bt_add_goods.setPreferredSize(new Dimension(100, 30));
		bt_add_goods.setFont(new Font("楷体",Font.BOLD,15));
		bt_add_goods.setBackground(new Color(0xF0F0F0));
		bt_add_goods.setBorder(border);
		bt_add_goods.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_add_goods.addActionListener((e)->{
			if(table_left.getSelectedRow()!=-1) {
				goodsInfo.clear();//清空数据
				new Goodsfarme(MyFrame.this,true,goodsInfo);
				//点击关闭，或取消
				if(goodsInfo.isEmpty()) return ;
				//添加到数据库
				try {
					//图书
					Object[] id=base.queryArrayHandler("select id,inventoryNums from bookinfo where  BookName=? and author=?",
							                             goodsInfo.get(1),goodsInfo.get(4));//是否存在该书籍（查询id，库存数量）
					String  wholeNum;
					if(id==null||id.length==0) {//数据库无此书	
						goodsInfo.add(0,bookNum+"");//设置书号
						tableModel_right.addRow(goodsInfo.toArray());//填写的获取的数据到面板
						wholeNum=goodsInfo.get(goodsInfo.size()-1);//批发数
						goodsInfo.remove(goodsInfo.size()-1);//移除批发数
						goodsInfo.add(wholeNum);//添加库存量
				    	base.update(insertOfBook,goodsInfo.toArray());
				    	 //库单内容
					    base.update(insertOfLibC,tableModel_left.getValueAt(table_left.getSelectedRow(),
					    		                                            0),bookNum,wholeNum);
				    	bookNum++;
				    }else {//数据库存在此书，只更新库存数量
				    	wholeNum=goodsInfo.get(goodsInfo.size()-1);//批发数
				    	goodsInfo.clear();//清空
				    	Object[] book=base.queryArrayHandler(queryOfBook,id[0]);//书籍信息
				    	for(int i=0;i<book.length;i++) {
				    		goodsInfo.add(book[i]+"");
				    	}
				    	goodsInfo.add(wholeNum);
//				    	goodsInfo.add(0,id[0]+"");//设置书号
						tableModel_right.addRow(goodsInfo.toArray());//填写的获取的数据到面板
//				    	wholeNum=goodsInfo.get(goodsInfo.size()-1);//批发数
//						goodsInfo.remove(goodsInfo.size()-1);//移除批发数
//						goodsInfo.remove(0);//移除书号
//						goodsInfo.add((int)id[1]+Integer.parseInt(wholeNum)+"");//添加库存量
//                        goodsInfo.add(id[0]+"");//选择已有id进行添加
//				    	base.update(updatetOfBook,goodsInfo.toArray());
						base.update("update bookinfo set inventoryNums=? where id=?",(int)id[1]+Integer.parseInt(wholeNum)+"",id[0]);//更新库存
				    	//库单内容
					    base.update(insertOfLibC,tableModel_left.getValueAt(table_left.getSelectedRow(),
					    		                                            0),id[0],wholeNum);
				    }
					TableUtils.moveToFinal(table_right, tableModel_right);
			
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					return ;
				}
				//清空
				goodsInfo.clear();
				JOptionPane.showMessageDialog(MyFrame.this,"增加成功");
			}
			else
				JOptionPane.showMessageDialog(MyFrame.this,"请选中所需修改的库单");
		});
		pl_north.add(bt_add_goods);
		//修改商品 1.改批发数量,bookid(arrivalregistcontent) 2.改书的基本信息（可能改变书名，作者，这样的话，可能要删除bookinfo）
		bt_update_goods=new JButton("修改商品项");
		bt_update_goods.setPreferredSize(new Dimension(100, 30));
		bt_update_goods.setFont(new Font("楷体",Font.BOLD,15));
		bt_update_goods.setBackground(new Color(0xF0F0F0));
		bt_update_goods.setBorder(border);
		bt_update_goods.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_update_goods.addActionListener(e->{
			if((selectRow=table_right.getSelectedRow())!=-1) {
				goodsInfo.clear();
				
				//获取选中行数据
			    for(int  i=1;i<columnNames_right.length;i++) {
			    	goodsInfo.add(tableModel_right.getValueAt(selectRow, i)+"");
			    }
			    
			    //弹窗
				new Goodsfarme(MyFrame.this, true,goodsInfo);
				
				//入数据库（名字，作者一致图书称为一种）流程：删除原库单-》新建库单（更新库单时别忘相关联的信息）
				try {
					//1.删除原书籍的数据库记录（删除库单内容，修改图书库存数，但不删除，修改图书的其他信息，（图书是共享的））
					{
						String  bookID=tableModel_right.getValueAt(table_right.getSelectedRow(),0)+"";
						String  wholeNum=tableModel_right.getValueAt(table_right.getSelectedRow(),columnNames_right.length-1)+"";
						Object[] libc_id=base.queryArrayHandler("select id from arrivalregistcontent where libraryID=? and bookId=? and wholeSaleNum=?",//查找库存内容ID
									                                                 tableModel_left.getValueAt(table_left.getSelectedRow(),0),//库单ID
									                                                                                          bookID,wholeNum);
						base.update("delete from arrivalregistcontent where id=?",libc_id[0]);//删除库单内容表
						Object[] bookNum=base.queryArrayHandler("select inventoryNums from bookinfo where id=?",bookID);//获取图书库存
						base.update("update bookinfo set inventoryNums=? where id=?",Integer.parseInt(bookNum[0]+"")-Integer.parseInt(wholeNum),bookID);//修改图书库存
					}
					//2.装填新数据
					{
						Object[] id=base.queryArrayHandler("select id,inventoryNums from bookinfo where  BookName=? and author=?",
								                             goodsInfo.get(1),goodsInfo.get(4));
						String wholeNum;
						if(id==null||id.length==0) {//数据库无此书	
							goodsInfo.add(0,bookNum+"");//设置书号
							setRowData(table_right.getSelectedRow(),tableModel_right,goodsInfo.toArray());//填写的获取的数据到面板
							wholeNum=goodsInfo.get(goodsInfo.size()-1);//批发数
							goodsInfo.remove(goodsInfo.size()-1);//移除批发数
							goodsInfo.add(wholeNum);//添加库存量
					    	base.update(insertOfBook,goodsInfo.toArray());
					    	 //库单内容
						    base.update(insertOfLibC,tableModel_left.getValueAt(table_left.getSelectedRow(),
						    		                                            0),bookNum,wholeNum);
					    	bookNum++;
					    }else {//数据库存在此书，只更新库存数量
//					    	wholeNum=goodsInfo.get(goodsInfo.size()-1);//批发数
//					    	goodsInfo.clear();//清空
//					    	Object[] book=base.queryArrayHandler(queryOfBook,id[0]);//书籍信息
//					    	for(int i=0;i<book.length;i++) {
//					    		goodsInfo.add(book[i]+"");1
//					    	}
//					    	goodsInfo.add(wholeNum);
//					    	setRowData(table_right.getSelectedRow(),tableModel_right,goodsInfo.toArray());//填写的获取的数据到面板
//							base.update("update bookinfo set inventoryNums=? where id=?",(int)id[1]+Integer.parseInt(wholeNum)+"",id[0]);//更新库存
//					    	//库单内容
//						    base.update(insertOfLibC,tableModel_left.getValueAt(table_left.getSelectedRow(),
//						    		                                            0),id[0],wholeNum);
					    	goodsInfo.add(0,id[0]+"");//设置书号
					    	setRowData(table_right.getSelectedRow(),tableModel_right,goodsInfo.toArray());//填写的获取的数据到面板
					    	goodsInfo.remove(0);
					    	wholeNum=goodsInfo.get(goodsInfo.size()-1);//批发数
							goodsInfo.remove(goodsInfo.size()-1);//移除批发数
							goodsInfo.add((int)id[1]+Integer.parseInt(wholeNum)+"");//添加库存量
							goodsInfo.add(id[0]+"");
					    	base.update(updateOfBook,goodsInfo.toArray());
			
					    	 //库单内容
						    base.update(insertOfLibC,tableModel_left.getValueAt(table_left.getSelectedRow(),
						    		                                            0),id[0],wholeNum);
					    }
					}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					return ;
				}
				
				goodsInfo.clear();//清空
				JOptionPane.showMessageDialog(MyFrame.this,"修改成功");
			}else {
				JOptionPane.showMessageDialog(MyFrame.this,"请选中所需修改的商品项");
				return ;
			}
		});
		pl_north.add(bt_update_goods);
		   //删除商品 1.库单内容，2.书籍的库存 
		bt_delete_goods=new JButton("删除商品项");
		bt_delete_goods.setPreferredSize(new Dimension(100, 30));
		bt_delete_goods.setFont(new Font("楷体",Font.BOLD,15));
		bt_delete_goods.setBackground(new Color(0xF0F0F0));
		bt_delete_goods.setBorder(border);
		bt_delete_goods.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_delete_goods.addActionListener(e->{
			if((selectRow=table_right.getSelectedRow())!=-1) {
				if(JOptionPane.showConfirmDialog(MyFrame.this,"确认要删除吗？", "提示", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION) {
					try {
						String  bookID=tableModel_right.getValueAt(table_right.getSelectedRow(),0)+"";
						String  wholeNum=tableModel_right.getValueAt(table_right.getSelectedRow(),columnNames_right.length-1)+"";
						Object[] libc_id=base.queryArrayHandler("select id from arrivalregistcontent where libraryID=? and bookId=? and wholeSaleNum=?",//查找库存内容ID
								                                                 tableModel_left.getValueAt(table_left.getSelectedRow(),0),//库单ID
								                                                                                          bookID,wholeNum);
//					System.out.println("库单ID="+tableModel_left.getValueAt(table_left.getSelectedRow(),0)+
//								       "书籍ID="+bookID+
//								       "批发数量="+wholeNum);
					base.update("delete from arrivalregistcontent where id=?",libc_id[0]);//删除库单内容表
					Object[] bookNum=base.queryArrayHandler("select inventoryNums from bookinfo where id=?",bookID);//获取图书库存
					base.update("update bookinfo set inventoryNums=? where id=?",Integer.parseInt(bookNum[0]+"")-Integer.parseInt(wholeNum),bookID);//修改图书库存
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						return ;
					}
					tableModel_right.removeRow(selectRow);//移除
					JOptionPane.showMessageDialog(MyFrame.this,"删除成功");
				}
			}else {
				JOptionPane.showMessageDialog(MyFrame.this,"请选中所需删除的商品项");
			}
		});
		pl_north.add(bt_delete_goods);
		//调间距
		JLabel lb=new JLabel();
		lb.setPreferredSize(new Dimension(800,1));
		pl_north.add(lb);
		
		   //取消入库
		bt_cancel=new JButton("退出");
		bt_cancel.setPreferredSize(new Dimension(100, 30));
		bt_cancel.setFont(new Font("楷体",Font.BOLD,15));
		bt_cancel.setBackground(new Color(0xF0F0F0));
		bt_cancel.setBorder(border);
		bt_cancel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_cancel.addActionListener(e->{
			dispose();
		});
		pl_north.add(bt_cancel);
		
		/*中部*/
		split_center=new JSplitPane();
		split_center.setDividerSize(6);
		split_center.setDividerLocation(300);
		split_center.setOneTouchExpandable(true);
		c.add(BorderLayout.CENTER,split_center);
		  //左边
		pl_center_left=new JPanel(new BorderLayout());
		pl_center_left.setBackground(Color.white);
		split_center.setLeftComponent(pl_center_left);
		      //表格
		
		tableModel_left=new DefaultTableModel(columnNames_left,0);
		table_left=new JTable(tableModel_left);
		table_left.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				showLibData();
			}
		});
		JScrollPane sp_center_left=new JScrollPane(table_left);
		sp_center_left.getViewport().setOpaque(false);
		sp_center_left.setBackground(Color.WHITE);
		pl_center_left.add(BorderLayout.CENTER,sp_center_left);
		
		//右边
		pl_center_right=new JPanel(new BorderLayout());
		pl_center_right.setBackground(Color.white);
		split_center.setRightComponent(pl_center_right);
		split_center.setDividerLocation(400);
		       //表格
		tableModel_right=new DefaultTableModel(columnNames_right,0);
		table_right=new JTable(tableModel_right);
		JScrollPane sp_center_right=new JScrollPane(table_right);
		sp_center_right.getViewport().setOpaque(false);
		sp_center_right.setBackground(Color.WHITE);
		pl_center_right.add(BorderLayout.CENTER,sp_center_right);
		
		/*底部*/
		pl_south=new JPanel(null);
		pl_south=new JPanel(new FlowLayout(FlowLayout.CENTER,30, 10));
		pl_south.setBackground(blue);
		pl_south.setPreferredSize(new Dimension(0,20));
		c.add(BorderLayout.SOUTH,pl_south);
		
		
//		showAllLib();//显示数据库中的库单数据
		TableUtils.interlacedColorChange(table_left,null,null);
		TableUtils.interlacedColorChange(table_right,null,null);
		setTitle("到货登记(入库)");
		setSize(1600,685);
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		setLocationRelativeTo(owner);
		setVisible(true);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
        new MyFrame(null,true);
	}

	/**
	 * 修改库单界面
	 * 
	 * @author ZC
	 *
	 */
	class LibraryList extends JDialog {

		private static final long serialVersionUID = 1L;

		private JPanel pl_flow;
		private JLabel lb_title;//标题
		private JLabel lb_sellDate;
		private JTextField tf_sellDate;//到货日期
		private JLabel lb_note;
		private JTextField tf_note;//备注
		private JLabel lb_purchasingAgent;
		private JTextField tf_purchasingAgent;//采购员
		private JLabel lb_SourceOfSupply;
		private JTextField tf_SourceOfSupply;//货源
		

		private JButton bt_sure;// 修改
		private JButton bt_cancel;// 取消
		//样式
//		private String pattern="yyyy-MM-dd";//日期
		private Color color2 = new Color(255, 255, 225);
		private Font font = new Font("宋体", Font.BOLD, 18);
		//辅助填写数据
		private List<JTextField> list_tf=new ArrayList<JTextField>();//所有输入框

		/**
		 * 1.通过插入无文字透明标签调整距理（仅限于流式布局）
		 * @param width
		 * @param height
		 * @param c 需要调整的组件
		 */
		public void insertJLabel(int width,int height,Container c) {
			JLabel lb=new JLabel();
			lb.setPreferredSize(new Dimension(width,height));
//			lb.setOpaque(true);
//			lb.setBackground(Color.red);
			c.add(lb);
		}
		/**
		 * 2.创建带文字的按钮
		 * @param text
		 * @return
		 */
		public JButton createJButton(String text) {
			JButton bt=new JButton();
			bt=new JButton(text);
	        bt.setPreferredSize(new Dimension(90, 30));
			bt.setFont(new Font("楷体",Font.BOLD,15));
			bt.setBackground(new Color(0xF0F0F0));
			bt.setBorder(border);
			bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			return bt;
		}
		public JButton createJButton(String text,int width) {
			JButton bt=new JButton();
			bt=new JButton(text);
	        bt.setPreferredSize(new Dimension(width, 30));
			bt.setFont(new Font("楷体",Font.BOLD,15));
			bt.setBackground(new Color(0xF0F0F0));
			bt.setBorder(border);
			bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			return bt;
		}
		public LibraryList(JDialog frame, boolean modal,List<String> LibraryInfo) {
			super(frame, modal);
			Container c = getContentPane();
			Color color0 = new Color(74, 101, 132);
			c.setBackground(color0);
			c.setLayout(new FlowLayout());
			//顶部间隔
            insertJLabel(650,25,c);
			// 中部面板
			pl_flow = new JPanel(new FlowLayout(FlowLayout.LEFT));// 流布局
			pl_flow.setPreferredSize(new Dimension(650, 250));
			Color color1 = new Color(222, 231, 239);
			pl_flow.setBackground(color1);
			c.add(pl_flow);
			
            //1.标题
			//1.1间距 
			insertJLabel(270,20, pl_flow);
			//1.2标题
			lb_title = new JLabel("批发单修改");
			lb_title.setFont(font);
			lb_title.setPreferredSize(new Dimension(350, 40));
			pl_flow.add(lb_title);
            
			//2.采购员
			//2.1标签
			lb_purchasingAgent = new JLabel("   采购员:");
			lb_purchasingAgent.setFont(font);
			lb_purchasingAgent.setPreferredSize(new Dimension(100, 40));
			pl_flow.add(lb_purchasingAgent);
            //2.2输入框
			tf_purchasingAgent = new JTextField();
			tf_purchasingAgent.setFont(font);
			tf_purchasingAgent.setPreferredSize(new Dimension(495, 25));
			tf_purchasingAgent.setBackground(color2);
			tf_purchasingAgent.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_purchasingAgent);
			list_tf.add(tf_purchasingAgent);

            //3.到货日期
			//3.1标签
			lb_sellDate = new JLabel(" 到货日期:");
			lb_sellDate.setFont(font);
			lb_sellDate.setPreferredSize(new Dimension(100, 40));
			pl_flow.add(lb_sellDate);
            //3.2输入框
			tf_sellDate = new JTextField();
			tf_sellDate.setFont(font);
			tf_sellDate.setPreferredSize(new Dimension(495, 25));
			tf_sellDate.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			MyCalendar ser =  MyCalendar.getInstance();//带日历面板，必须再加到面板前写
			ser.register(tf_sellDate);
			
			pl_flow.add(tf_sellDate);
			list_tf.add(tf_sellDate);
             
			//那条横线
			insertJLabel(100, 1, pl_flow);
			JLabel label2 = new JLabel();// 填充板
			label2.setPreferredSize(new Dimension(495, 3));
			label2.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
			pl_flow.add(label2);

			//4.货源
			//4.1标签
			lb_SourceOfSupply = new JLabel("     货源:");
			lb_SourceOfSupply.setFont(font);
			lb_SourceOfSupply.setPreferredSize(new Dimension(100, 40));
			pl_flow.add(lb_SourceOfSupply);
            //4.2输入框
			tf_SourceOfSupply = new JTextField();
			tf_SourceOfSupply.setFont(font);
			tf_SourceOfSupply.setPreferredSize(new Dimension(495, 25));
			tf_SourceOfSupply.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_SourceOfSupply);
			list_tf.add(tf_SourceOfSupply);
			
			//5.备注
			//5.1标签
			lb_note = new JLabel("     备注:");
			lb_note.setFont(font);
			lb_note.setPreferredSize(new Dimension(100, 40));
			pl_flow.add(lb_note);
            //5.2备注输入
			tf_note = new JTextField();
			tf_note.setFont(font);
			tf_note.setPreferredSize(new Dimension(495, 25));
			tf_note.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_note);
			list_tf.add(tf_note);
			
			//5.确认，取消
			insertJLabel(600, 20, c);//调整间距
			bt_sure=createJButton("确定");
			bt_sure.addActionListener(e->{
				
				//传回数据,使用后清空
				for(int i=0;i<list_tf.size();i++) {
					LibraryInfo.add(list_tf.get(i).getText());
				}
    			dispose();
			});
			c.add(bt_sure);
			//5.1取消
			insertJLabel(250, 20, c);//调整间距
			bt_cancel=createJButton("取消");
			bt_cancel.addActionListener(e->{
				dispose();
			});
			c.add(bt_cancel);
			
			//填充原数据
			for(int i=0;i<list_tf.size();i++) {
				list_tf.get(i).setText(LibraryInfo.get(i));
			}
			LibraryInfo.clear();//清空
			
			setTitle("批发单修改");
			setSize(700, 390);
			setResizable(false);// 不可增加大小
			setLocationRelativeTo(null);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setVisible(true);
		}
		
		
	}

	/**
	 * 增加商品界面
	 * @author ZC
	 *
	 */
	public class Goodsfarme extends JDialog{
		private static final long serialVersionUID = 1L;
		private JLabel lb_bookName;//书名
		private JTextField tf_bookName;
		private JLabel lb_bookAuthor;//作者
		private JTextField tf_bookAuthor;
		private JLabel lb_bookType;
		private JComboBox<String> cbx_bookType;//类别
		private JLabel lb_EveryDiscount;
		private JComboBox<String> cbx_EveryDiscount;//按本折扣
		private JLabel lb_MemberDiscount;
		private JComboBox<String> cbx_MemberDiscount;//会员打折
		private JLabel lb_startCount;
		private JTextField tf_startCount;//初期库存
		private JLabel lb_publishHouse ;
		private JTextField tf_publishHouse ;//出版社
		private JLabel lb_costPrice  ;
		private JTextField tf_costPrice  ;//成本价
		private JLabel lb_bookPrice;
		private JTextField tf_bookPrice;//定价
		private JLabel lb_retailPrice;
		private JTextField tf_retailPrice;//零售价
		private JLabel lb_retailDiscount;
		private JTextField tf_retailDiscount;//零售折扣
		private JLabel lb_wholsalePrice;
		private JTextField tf_wholsalePrice;//批发价
		private JLabel lb_wholDiscount;
		private JTextField tf_wholDiscount;//批发折扣
		
		private JLabel lb_vipPrice;
		private JTextField tf_vipPrice;//会员价
		private JLabel lb_countMax;
		private JTextField tf_countMax;//库存下限
		private JLabel lb_countMin;
		private JTextField tf_countMin;//库存上限
		private JLabel lb_wholeNum;
		private JTextField tf_wholeNum;//库存上限
		
		private JPanel pl_flow;
		private JLabel lb_title;//标题
		private JButton bt_sure;// 修改
		private JButton bt_cancel;// 取消
		//样式
		private Color color2 = new Color(255, 255, 225);
		private Font font = new Font("宋体", Font.BOLD, 18);
		//辅助填写数据
		private List<JComponent> list_tf=new ArrayList<JComponent>();//所有输入框
		private int[] doubleIndex={7,8,9,10,11,12,13};//double型数据下标
		private int[] intIndex= {5,14,15,16};//int型数据下标

		/**
		 * 1.通过插入无文字透明标签调整距理（仅限于流式布局）
		 * @param width
		 * @param height
		 * @param c 需要调整的组件
		 */
		public void insertJLabel(int width,int height,Container c) {
			JLabel lb=new JLabel();
			lb.setPreferredSize(new Dimension(width,height));
//			lb.setOpaque(true);
//			lb.setBackground(Color.red);
			c.add(lb);
		}
		/**
		 * 2.创建带文字的按钮
		 * @param text
		 * @return
		 */
		public JButton createJButton(String text) {
			JButton bt=new JButton();
			bt=new JButton(text);
	        bt.setPreferredSize(new Dimension(90, 30));
			bt.setFont(new Font("楷体",Font.BOLD,15));
			bt.setBackground(new Color(0xF0F0F0));
			bt.setBorder(border);
			bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			return bt;
		}
		public JButton createJButton(String text,int width) {
			JButton bt=new JButton();
			bt=new JButton(text);
	        bt.setPreferredSize(new Dimension(width, 30));
			bt.setFont(new Font("楷体",Font.BOLD,15));
			bt.setBackground(new Color(0xF0F0F0));
			bt.setBorder(border);
			bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			return bt;
		}
		/**
		 * 行线
		 */
		public void createLine(int width,int height,JPanel pl) {
			JLabel lb = new JLabel();// 填充板
			lb.setPreferredSize(new Dimension(width,height));
			lb.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
			pl.add(lb);
		}
		public  Goodsfarme(JDialog frame, boolean modal,List<String> goodsInfo) {
			super(frame, modal);
			Container c = getContentPane();
			Color color0 = new Color(74, 101, 132);
			c.setBackground(color0);
			c.setLayout(new FlowLayout());
			//顶部间隔
            insertJLabel(650,25,c);
			// 中部面板
			pl_flow = new JPanel(new FlowLayout(FlowLayout.LEFT));// 流布局
			pl_flow.setPreferredSize(new Dimension(650, 470));
			Color color1 = new Color(222, 231, 239);
			pl_flow.setBackground(color1);
			c.add(pl_flow);
			
            //1.标题
			//1.1间距 
			insertJLabel(230,20, pl_flow);
			
			//1.2标题
			lb_title = new JLabel("图书基本资料");
			lb_title.setFont(new Font("楷体",Font.BOLD,30));
			lb_title.setPreferredSize(new Dimension(350, 40));
			pl_flow.add(lb_title);
            
			//2.按本折扣
			//2.1标签
			insertJLabel(40,20, pl_flow);
			insertJLabel(20,1,pl_flow);
			lb_EveryDiscount = new JLabel("按本折扣:");
			lb_EveryDiscount.setFont(font);
			lb_EveryDiscount.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_EveryDiscount);
            //2.2输入框
			cbx_EveryDiscount = new JComboBox<String>(new String[]{"Yes","No"});
			cbx_EveryDiscount.setFont(font);
			cbx_EveryDiscount.setPreferredSize(new Dimension(100, 25));
			cbx_EveryDiscount.setBackground(color2);
			cbx_EveryDiscount.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(cbx_EveryDiscount);
			list_tf.add(cbx_EveryDiscount);

            //3.书名
			//3.1标签
			insertJLabel(20,1, pl_flow);
			lb_bookName = new JLabel("书名:");
			lb_bookName.setFont(font);
			lb_bookName.setPreferredSize(new Dimension(50, 40));
			pl_flow.add(lb_bookName);
            //3.2输入框
			tf_bookName = new JTextField();
			tf_bookName.setFont(font);
			tf_bookName.setPreferredSize(new Dimension(295, 25));
			tf_bookName.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_bookName);
			list_tf.add(tf_bookName);
             
//			//那条横线
//			createLine(400,3, pl_flow);

			//4.会员打折
			//4.1标签
			insertJLabel(20,1, pl_flow);
			insertJLabel(20,1,pl_flow);
			lb_MemberDiscount = new JLabel("会员打折:");
			lb_MemberDiscount.setFont(font);
			lb_MemberDiscount.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_MemberDiscount);
            //4.2输入框
			cbx_MemberDiscount = new JComboBox<String>(new String[]{"Yes","No"});
			cbx_MemberDiscount.setFont(font);
			cbx_MemberDiscount.setPreferredSize(new Dimension(100, 25));
			cbx_MemberDiscount.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(cbx_MemberDiscount);
			list_tf.add(cbx_MemberDiscount);
			
			//5.图书类型
			//5.1标签
			insertJLabel(20,1, pl_flow);
			lb_bookType = new JLabel("图书类型:");
			lb_bookType.setFont(font);
			lb_bookType.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_bookType);
            //5.2输入框
			cbx_bookType = new JComboBox<String>(new String[]{"教辅","文学","地理","考试","历史","音乐","其他"});
			cbx_bookType.setFont(font);
			cbx_bookType.setPreferredSize(new Dimension(180, 25));
			cbx_bookType.setBackground(color2);
			cbx_bookType.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(cbx_bookType);
			list_tf.add(cbx_bookType);
			
			//6.作者
			//1标签
			insertJLabel(100,1, pl_flow);
			insertJLabel(20,1, pl_flow);
			lb_bookAuthor = new JLabel("作者:");
			lb_bookAuthor.setFont(font);
			lb_bookAuthor.setPreferredSize(new Dimension(50, 40));
			pl_flow.add(lb_bookAuthor);
            //2输入框
			tf_bookAuthor = new JTextField();
			tf_bookAuthor.setFont(font);
			tf_bookAuthor.setPreferredSize(new Dimension(140, 25));
			tf_bookAuthor.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_bookAuthor);
			list_tf.add(tf_bookAuthor);
			
			//7.初期库存
			//1标签
			insertJLabel(20,1, pl_flow);
			lb_startCount = new JLabel("初期库存:");
			lb_startCount.setFont(font);
			lb_startCount.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_startCount);
            //2输入框
			tf_startCount = new JTextField();
			tf_startCount.setText("0");
			tf_startCount.setFont(font);
			tf_startCount.setPreferredSize(new Dimension(255, 25));
			tf_startCount.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_startCount);
			list_tf.add(tf_startCount);
			
			//行线
			insertJLabel(20,1, pl_flow);
			insertJLabel(20,1, pl_flow);
			createLine(578, 3, pl_flow);
			
			//8.出版社publishHouse
			//1标签
			insertJLabel(20,1, pl_flow);
			insertJLabel(20,1, pl_flow);
			lb_publishHouse = new JLabel("出版社:");
			lb_publishHouse.setFont(font);
			lb_publishHouse.setPreferredSize(new Dimension(70, 40));
			pl_flow.add(lb_publishHouse);
            //2输入框
			tf_publishHouse = new JTextField();
			tf_publishHouse.setText("出版社");
			tf_publishHouse.setFont(font);
			tf_publishHouse.setPreferredSize(new Dimension(500, 25));
			tf_publishHouse.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_publishHouse);
			list_tf.add(tf_publishHouse);
			
			//9.成本价
			//1标签
			insertJLabel(20,1, pl_flow);
			insertJLabel(20,1, pl_flow);
			lb_costPrice = new JLabel("成本价:");
			lb_costPrice.setFont(font);
			lb_costPrice.setPreferredSize(new Dimension(70, 40));
			pl_flow.add(lb_costPrice);
            //2输入框
			tf_costPrice = new JTextField();
			tf_costPrice.setFont(font);
			tf_costPrice.setText("45.00");
			tf_costPrice.setPreferredSize(new Dimension(120, 25));
			tf_costPrice.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_costPrice);
			list_tf.add(tf_costPrice);
			
			//10.定价
			//1标签
			insertJLabel(20,1, pl_flow);
			lb_bookPrice = new JLabel("定价:");
			lb_bookPrice.setFont(font);
			lb_bookPrice.setPreferredSize(new Dimension(50, 40));
			pl_flow.add(lb_bookPrice);
            //2输入框
			tf_bookPrice = new JTextField();
			tf_bookPrice.setText("60.00");
			tf_bookPrice.setFont(font);
			tf_bookPrice.setPreferredSize(new Dimension(120, 25));
			tf_bookPrice.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_bookPrice);
			list_tf.add(tf_bookPrice);
			
			//11.零售价
			//1标签
			insertJLabel(10,1, pl_flow);
			lb_retailPrice = new JLabel("零售价:");
			lb_retailPrice.setFont(font);
			lb_retailPrice.setPreferredSize(new Dimension(70, 40));
			pl_flow.add(lb_retailPrice);
            //2输入框
			tf_retailPrice = new JTextField();
			tf_retailPrice.setText("45.00");
			tf_retailPrice.setFont(font);
			tf_retailPrice.setPreferredSize(new Dimension(80, 25));
			tf_retailPrice.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_retailPrice);
			list_tf.add(tf_retailPrice);
			
			//12.零售折扣
			//1标签
			insertJLabel(20,1, pl_flow);
			insertJLabel(20,1, pl_flow);
			lb_retailDiscount = new JLabel("零售折扣:");
			lb_retailDiscount.setFont(font);
			lb_retailDiscount.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_retailDiscount);
            //2输入框
			tf_retailDiscount = new JTextField();
			tf_retailDiscount.setText("0.85");
			tf_retailDiscount.setFont(font);
			tf_retailDiscount.setPreferredSize(new Dimension(100, 25));
			tf_retailDiscount.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_retailDiscount);
			list_tf.add(tf_retailDiscount);
			
			//13.批发价wholsalePrice
			//1标签
			insertJLabel(20,1, pl_flow);
			lb_wholsalePrice = new JLabel("批发价:");
			lb_wholsalePrice.setFont(font);
			lb_wholsalePrice.setPreferredSize(new Dimension(70, 40));
			pl_flow.add(lb_wholsalePrice);
            //2输入框
			tf_wholsalePrice = new JTextField();
			tf_wholsalePrice.setText("55.00");
			tf_wholsalePrice.setFont(font);
			tf_wholsalePrice.setPreferredSize(new Dimension(100, 25));
			tf_wholsalePrice.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_wholsalePrice);
			list_tf.add(tf_wholsalePrice);
			
			//14.批发折扣wholDiscount
			//1标签
			insertJLabel(10,1, pl_flow);
			lb_wholDiscount = new JLabel("批发折扣:");
			lb_wholDiscount.setFont(font);
			lb_wholDiscount.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_wholDiscount);
            //2输入框
			tf_wholDiscount = new JTextField();
			tf_wholDiscount.setText("0.75");
			tf_wholDiscount.setFont(font);
			tf_wholDiscount.setPreferredSize(new Dimension(60, 25));
			tf_wholDiscount.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_wholDiscount);
			list_tf.add(tf_wholDiscount);
			
			//15.会员售价
			//1标签
			insertJLabel(20,1, pl_flow);
			insertJLabel(20,1, pl_flow);
			lb_vipPrice = new JLabel("会员售价:");
			lb_vipPrice.setFont(font);
			lb_vipPrice.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_vipPrice);
            //2输入框
			tf_vipPrice = new JTextField();
			tf_vipPrice.setText("58.00");
			tf_vipPrice.setFont(font);
			tf_vipPrice.setPreferredSize(new Dimension(480, 25));
			tf_vipPrice.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_vipPrice);
			list_tf.add(tf_vipPrice);
			
			//17库存上限
			//1标签
			insertJLabel(20,1, pl_flow);
			insertJLabel(20,1, pl_flow);
			lb_countMax = new JLabel("库存上限:");
			lb_countMax.setFont(font);
			lb_countMax.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_countMax);
            //2输入框
			tf_countMax = new JTextField();
			tf_countMax.setText("1000");
			tf_countMax.setFont(font);
			tf_countMax.setPreferredSize(new Dimension(480, 25));
			tf_countMax.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_countMax);
			list_tf.add(tf_countMax);
			
			//16.库存下限
			//1标签
			insertJLabel(20,1, pl_flow);
			insertJLabel(20,1, pl_flow);
			lb_countMin = new JLabel("库存下限:");
			lb_countMin.setFont(font);
			lb_countMin.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_countMin);
            //2输入框
			tf_countMin = new JTextField();
			tf_countMin.setText("0");
			tf_countMin.setFont(font);
			tf_countMin.setPreferredSize(new Dimension(280, 25));
			tf_countMin.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_countMin);
			list_tf.add(tf_countMin);
			
			
			
			//18.批发数量
			insertJLabel(20,1, pl_flow);
			lb_wholeNum= new JLabel("批发数量:");
			lb_wholeNum.setFont(font);
			lb_wholeNum.setPreferredSize(new Dimension(90, 40));
			pl_flow.add(lb_wholeNum);
            //2输入框
			tf_wholeNum= new JTextField();
			tf_wholeNum.setText("20");
			tf_wholeNum.setFont(font);
			tf_wholeNum.setPreferredSize(new Dimension(75, 25));
			tf_wholeNum.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_wholeNum);
			list_tf.add(tf_wholeNum);
			
			//确认，取消
			insertJLabel(600, 5, c);//调整间距
			bt_sure=createJButton("确定");
			bt_sure.addActionListener(e->{
				goodsInfo.clear();//清空
				//1.检查数据是否填写
				for(int i=0;i<list_tf.size();i++) {
					if(list_tf.get(i) instanceof JTextField) {
						JTextField tf=(JTextField)list_tf.get(i);
						String str=tf.getText();
                        if ("".equals(str)||str.length()==0) {
                        	JOptionPane.showMessageDialog(Goodsfarme.this,"请将数据填写完整");
                        	return ;
                        }
					}
				}
				//2.检查是否合理
				try {
					for(int i=0;i<intIndex.length;i++) {
						JTextField tf=(JTextField)list_tf.get(intIndex[i]);
						Integer.parseInt(tf.getText());
					}
					for(int i=0;i<doubleIndex.length;i++) {
						JTextField tf=(JTextField)list_tf.get(doubleIndex[i]);
						Double.parseDouble(tf.getText());
					}
				} catch (Exception e2) {
					// TODO: handle exception
					JOptionPane.showMessageDialog(Goodsfarme.this,"数据类型填写错误");
                	return ;
				}
				//3.获取填写数据
				for(int i=0;i<list_tf.size();i++) {
					if(list_tf.get(i) instanceof JTextField) {
						JTextField tf=(JTextField)list_tf.get(i);
                        goodsInfo.add(tf.getText());
					}else {
						@SuppressWarnings("unchecked")
						JComboBox<String> tf=(JComboBox<String>)list_tf.get(i);
						goodsInfo.add((String)tf.getSelectedItem());
					}
				}
				dispose();
			});
			c.add(bt_sure);
			//5.1取消
			insertJLabel(250, 20, c);//调整间距
			bt_cancel=createJButton("取消");
			bt_cancel.addActionListener(e->{
				dispose();
			});
			c.add(bt_cancel);
			
//			//设置初始值
//			for(int i=0;i<intIndex.length;i++) {
//				System.out.print(i+" ");
//				JTextField tf=(JTextField)list_tf.get(intIndex[i]);
//				tf.setText("1");
//			}
//			tf_countMin.setText("0");
//			tf_countMax.setText("1000");
//            for(int i=0;i<doubleIndex.length;i++) {
//            	JTextField tf=(JTextField)list_tf.get(doubleIndex[i]);
//				tf.setText("1.00");
//			}
			//装填原数据
			for(int i=0;i<goodsInfo.size();i++) {
				if(list_tf.get(i) instanceof JTextField) {
					JTextField tf=(JTextField)list_tf.get(i);
					tf.setText(goodsInfo.get(i));
				}else {
					@SuppressWarnings("unchecked")
					JComboBox<String> tf=(JComboBox<String>)list_tf.get(i);
					tf.setSelectedItem(goodsInfo.get(i));
				}
			}
			goodsInfo.clear();//清空
				
			setTitle("批发单修改");
			setSize(700, 600);
			setResizable(false);// 不可增加大小
			setLocationRelativeTo(null);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setVisible(true);
		}
	}
}
